package com.tm.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tm.CoreConstants;
import com.tm.model.EcStoreManage;
import com.tm.service.EcStoreManageService;
import com.tm.util.WeixinConfigUtil;

@Controller
@RequestMapping(value = "/storeView")
public class EcStoreManageController {
	
	@Autowired
	private EcStoreManageService esmService;

	/**
	 * 跳转店铺选择页面
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException 
	 * @throws Exception 
	 */
	@RequestMapping(value = "/list")
	public String list(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
		
		if(request.getSession().getAttribute("memberId") == null){
			response.sendRedirect(CoreConstants.SJ_DOMAIN);
		}
		
		/*****************************************加载微信jssdk 配置参数***************************************/
		Map<String, Object> rem = WeixinConfigUtil.getWxConfig(request);
		
		model.addAttribute("appId", rem.get("appId"));
		model.addAttribute("timestamp", rem.get("timestamp"));
		model.addAttribute("nonceStr", rem.get("nonceStr"));
		model.addAttribute("signature", rem.get("signature"));
		/*****************************************加载微信jssdk 配置参数***************************************/
		
		String areaId = request.getParameter("areaId");
		
		List<EcStoreManage> list = esmService.getEcStoreManageList(areaId);
		
		model.addAttribute("list", list);
		
		return "store/list";
	}
	
}
